class NanoUrlController < ApplicationController
  def index
    
  end
  
  def create    
    @nano_url = NanoUrl.new(params[:nano_url])
    if @nano_url.save
      newurl = "http://#{request.host_with_port}/#{@nano_url.id}"
      flash[:notice] = %q{Wow,Your NanoURL has been created.<br/>} + "<b></b>#{newurl}<br/>" + "<a href=\"#{newurl}\" target=\"_blank\">[Open in new window]</a>"
      
      redirect_to :action => :index
    else
      render :action => :index
    end       
  end
  
  def jump
    begin
      @nano_url = NanoUrl.find(params[:id])
      redirect_to @nano_url.url_link
    rescue ActiveRecord::RecordNotFound
      flash[:notice] = "Oops, the Nano URL doesn't exsit. => #{'http://' + request.host_with_port + '/' + params[:id]}"
      redirect_to :action => :index
    end
  end
end
